• frmRegistration_FirstRun.vb
  • project /
1 Imports System.Data.SqlClient
2
3 Public Class frmRegistration1
4
5     Sub Reset()
6         txtContactNo.Text =
""
7         txtEmailID.Text =
""
8         txtName.Text =
""
9         txtPassword.Text =
""
10         txtUserID.Text =
""
11     End Sub
12     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
13         End
14     End Sub
15
16     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
17         If txtUserID.Text =
"" Then
18             MessageBox.Show(
"Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
19             txtUserID.Focus()
20             Return
21         End If
22         If txtPassword.Text =
"" Then
23             MessageBox.Show(
"Please enter password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
24             txtPassword.Focus()
25             Return
26         End If
27         If txtName.Text =
"" Then
28             MessageBox.Show(
"Please enter name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
29             txtName.Focus()
30             Return
31         End If
32         If txtContactNo.Text =
"" Then
33             MessageBox.Show(
"Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
34             txtContactNo.Focus()
35             Return
36         End If
37
38         Try
39             con = New SqlConnection(cs)
40             con.Open()
41             Dim ct As String =
"select userid from registration where userid=@d1"
42             cmd = New SqlCommand(ct)
43             cmd.Parameters.AddWithValue(
"@d1", txtUserID.Text)
44             cmd.Connection = con
45             rdr = cmd.ExecuteReader()
46
47             If rdr.Read() Then
48                 MessageBox.Show(
"user id Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
49                 txtUserID.Text =
""
50                 txtUserID.Focus()
51                 If (rdr IsNot Nothing) Then
52                     rdr.Close()
53                 End If
54                 Return
55             End If
56
57             con = New SqlConnection(cs)
58             con.Open()
59
60             Dim cb As String =
"insert into Registration(userid, UserType, Password, Name, ContactNo, EmailID,JoiningDate,Active) VALUES (@d1,'Admin',@d3,@d4,@d5,@d6,@d7,'Yes')"
61             cmd = New SqlCommand(cb)
62             cmd.Connection = con
63             cmd.Parameters.AddWithValue(
"@d1", txtUserID.Text)
64             cmd.Parameters.AddWithValue(
"@d3", Encrypt(txtPassword.Text.Trim()))
65             cmd.Parameters.AddWithValue(
"@d4", txtName.Text)
66             cmd.Parameters.AddWithValue(
"@d5", txtContactNo.Text)
67             cmd.Parameters.AddWithValue(
"@d6", txtEmailID.Text)
68             cmd.Parameters.AddWithValue(
"@d7", Now)
69             cmd.ExecuteReader()
70             con.Close()
71             MessageBox.Show(
"Successfully Registered", "User", MessageBoxButtons.OK, MessageBoxIcon.Information)
72             Me.Hide()
73             frmLogin.Show()
74         Catch ex As Exception
75             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
76         End Try
77     End Sub
78
79     Private Sub frmRegistration1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
80         Reset()
81     End Sub
82 End Class


Gõ tìm kiếm nhanh...